/*
 * @Author: LiuYan
 * @Date: 2022-08-06 13:04:57
 * @LastEditors: 刘岩
 * @LastEditTime: 2023-07-28 14:37:08
 * @Description:
 */
const { HTTP } = require('./src/config')
const { VantResolver } = require('unplugin-vue-components/resolvers')
const ComponentsPlugin = require('unplugin-vue-components/webpack')
const autoprefixer = require('autoprefixer')
const PxToVwVh = require('@yik_l/px-to-vw-vh')
const { resolve } = require('path')
module.exports = {
  //基本路径
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  //构建时的输出目录
  outputDir: 'dist',
  //放置静态资源的目录
  assetsDir: './static',
  //不生成map文件
  productionSourceMap: false,
  //关闭每次保存都进行检测
  lintOnSave: false,
  devServer: {
    host: '0.0.0.0',
    open: false,
    port: process.env.VUE_APP_PORT,
    //页面自动热重载
    hot: true,
    // host: "127.0.0.1",
    proxy: HTTP.proxy && {
      //配置多个同域名代理
      ...Object.assign(
        ...HTTP.cross_prefix.map(p => {
          let item = {
            [p]: {
              target: HTTP.cross_domain,
              changeOrigin: true,
              pathRewrite: { [`^${p}`]: p },
            },
          }
          return item
        })
      ),
    },
  },
  configureWebpack: {
    plugins: [
      new PxToVwVh({
        viewportWidth: 375,
        vw: 'px',
      }),
      ComponentsPlugin({
        resolvers: [VantResolver()],
      }),
    ],
    resolve: {
      //引入模块时不带扩展
      extensions: ['.js', '.json', '.less', '.vue'],
      //指定node_modules,不需要再继续往上层寻找。
      modules: [resolve(__dirname, './node_modules')],
      alias: {
        '@': resolve('src'),
      },
    },
  },
  css: {
    loaderOptions: {
      postcss: {
        plugins: [autoprefixer()],
      },
    },
  },
}
